﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace TKToXML.Persistence.Repositories
{
    public abstract class BaseRepository<T>
    {
        public readonly ISession session;

        protected BaseRepository(ISession session)
        {
            this.session = session;
        }

        public virtual void SaveOrUpdate(T model)
        {
            session.SaveOrUpdate(model);
        }

        public virtual T Get(object primaryKey)
        {
            return (T)session.Get(typeof(T), primaryKey);
        }

        public virtual void Delete(T model)
        {
            session.Delete(model);
        }

        public virtual void RollBack()
        {
            session.Transaction.Rollback();
        }

        public virtual IList<T> GetAll()
        {
            return session.CreateCriteria(typeof(T)).List<T>();
        }
    }
}
